package com.ctshk.sapp.order.train.controller;

import cn.hutool.http.HttpUtil;
import com.ctshk.common.annotations.OperationLogAnnotation;
import com.ctshk.common.dto.Result;
import com.ctshk.common.enums.OperationLogModel;
import com.ctshk.common.enums.OperationLogType;
import com.ctshk.common.model.TokenUser;
import com.ctshk.common.web.support.BaseController;
import com.ctshk.rpc.order.train.req.TrainManualOrderReq;
import com.ctshk.rpc.order.train.service.ITrainManualOrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * <p>
 * 火车票手工单（外挂单） 前端控制器
 * </p>
 *
 * @author 彭柳霖
 * @since 2021-03-17
 */
@Api(value="预订中心-火车添加外挂单", tags="预订中心-火车添加外挂单")
@Slf4j
@RestController
@RequestMapping("/train-manual-order")
public class TrainManualOrderController extends BaseController {

    @DubboReference
    ITrainManualOrderService trainManualOrderService;

    @ApiOperation(value="添加外挂单", notes="添加外挂单")
    @OperationLogAnnotation(operModul = OperationLogModel.ORDER, operType = OperationLogType.ADD, operTitle = "添加外挂单", operDesc = "添加外挂单")
    @PostMapping("/save")
    public Result saveBusMaunalOrder(@RequestBody @Valid TrainManualOrderReq trainManualOrderReq) {
        TokenUser user = getCurrentUser(getRequest());
        return trainManualOrderService.addTrainManualOrder(trainManualOrderReq,user);
    }

    @GetMapping("/test")
    public Result test() {
        String url = "http://203.90.6.56/cts/Enquiry";
        String xml = "<?xml version=\"1.0\" encoding=\"BIG5\"?>\n" +
                "<Action strMethName=\"mtdListEffStation\">\n" +
                "    <Data>\n" +
                "        <strServCde>GZ</strServCde>\n" +
                "    </Data>\n" +
                "</Action>";
        String res = "";
        try {
            log.info("发起请求 url:{}, xml:{}", url, xml);
            res = HttpUtil.post(url, xml,5000);
            System.out.println(res);
        }catch (Exception e) {
            e.printStackTrace();
        }
        return Result.success(res);
    }
}
